(function () {
	//自定义true标签对象
	function trueTags(){}
	trueTags.prototype = {
		//初始化方法
		init:function(options){
			var that = this;
			//true标签的配置
			this.config = {
				//接口根路径
				basePath:'http://61.155.85.78:5012/trueMAEC',
				//接口参数
				deptid:'{BFA80019-0000-0000-432B-267E0000000E}',
				//debug开关，开启后用本地随机数据
				debugEnable:true
			};
			//全局true标签num
			this.globalNum = 1;
			//随机true标签id前缀
			this.idPrefix = 'tags_' + Math.random().toString().replace('.', '') + '_';
			//是否进入编辑状态
			this.isEditing = false;
			//临时数据存储
			this.tmpData = {};
			//封装好的最终数据
			this.dataJSON = {};
			this.comJSON = {};
			//当前编辑对象ID
			this.currentId = null;
			
			if(options){
				this.updateOption(options);
			}
			
			//获取wangEditor构造函数
			this.WE = window.wangEditor;
			this.createCustomToMenu(function(reParams){
				//点击菜单事件
		        reParams.menu.clickEvent = function (e) {
		        	//编辑状态=否
		        	that.isEditing = false;
		        	that.layerIn({e:e,editor:reParams.editor});
		        }
			});
			
			//拓展tag的自定义工具
			this.WE.plugin(function(){
				return that.customToolPlugin({that:that,this:this});
			});
			
			//页面渲染
			this.createCustomWraps();
			
			//定义弹出层大小
			this.layerSize = this.getPageSize();
			
			return this;
		},
		
		//弹出数据编辑层
		layerIn:function(params){
			var that = this;
			
			//清空
			this.clearCustomWrap();
			
			//数据初始化以及界面渲染
			this.initDataToRender();
			
			//打开弹出层
			layer.open({
	            type: 1,
	            area: [that.layerSize[2]-40+'px', that.layerSize[3]-40+'px'],
	            title: '插入标签',
	            content: $('#tagWrap'),
	            btn: ['确定', '取消'],
	            yes: function(index){
	            	//临时数据绑定到对象内部key=tagid，然后在编辑的时候通过tagid获取
					if(that.currentId){
						if(that.tmpData.zbid){
							//保存数据
							that.dataJSON[that.currentId] = that.tmpData;
							//通知编辑器
							if(that.isEditing){
								//remove
								var $delete = $('.wangeditor-menu-img-trash-o');
								$delete.click();
							}
							//insert
							var tagValue = that.$tagResultWrap.find(".JS_tagValue").text();
							var s = '<b class="tags" data-id="'+ that.currentId +'">'+ tagValue +'</b>';
	                        // 执行命令
	                        params.editor.command(params.e, 'insertHtml', s);
						}
                        
						//重置临时数据
						that.currentId = false;
						that.tmpData = {};
						that.isEditing = false;
						//关闭层
						layer.close(index);
					}else{
						layer.alert('请先点击结果预览中的测试按钮');
					}
	            },
	            cancel :function(){
	            	that.isEditing = false;
	            }
	        });
		},
		
		//注册trueTags菜单按钮
		createCustomToMenu:function(callback){
			var that = this;
			that.WE.createMenu(function (check) {
				var menuId = 'tags';
		        if (!check(menuId)) {
		            return;
		        }
		        var editor = this;
		        // 创建 menu 对象
		        var menu = new that.WE.Menu({
		            editor: editor,
		            id: menuId,
		            title: '插入标签',
		            // 正常状态和选中装下的dom对象，样式需要自定义
		            $domNormal: $('<a href="#" tabindex="-1"><i class="wangeditor-custom-icon-tags"></i></a>'),
		            $domSelected: $('<a href="#" tabindex="-1" class="selected"><i class="wangeditor-custom-icon-tags"></i></a>')
		        });
		        // 增加到editor对象中
		        editor.menus[menuId] = menu;
		        callback({menu:menu,editor:editor});
			})
		},
		
		//绑定事件
		bindEvent:function(params){
			params.obj.off(params.name).on(params.name,params.events);
		},
		
		//获取数据模型，回调中渲染界面
		initDataToRender:function(){
			var that = this;
			//指标及分组数据
			this.getJSON({
				url:that.config.basePath + "/trueDataController/getModelList.do?deptid="+that.config.deptid,
				callback:function(result){
					//渲染layer
                	var tables = result.data;
					that.createTableSelects(tables);
					//绑定事件
					that.bindEvent({
						obj:that.$tableWrap.find("select"),
						name:"change",
						events:function(){
							//change时获取分组
							var modelId = $(this).val();
							//渲染分组
							var $optionSelected = $(this).find('option:selected');
							var tableName =  $optionSelected.attr("data-tablename");
                    		var keyClicked = $optionSelected.attr("data-tbKey");
		                    var groups = tables[keyClicked].tyzdxList;
		                    that.createGroupSpans({
		                    	groups:groups,
		                    	tableName:tableName,
		                    	modelId:modelId
		                    });
		                    //分组绑定事件
							that.bindEvent({
								obj:that.$groupWrap.find(".label-item"),
								name:"click",
								events:function(){
									that.$groupWrap.find('.label-item').removeClass('checked');
							        $(this).addClass('checked');
							        
							        //要素数据
				                    that.getFiledTableData({
				                    	modelId:modelId,
				                    	callback:function(){
						                    //要素绑定事件
											that.bindEvent({
												obj:that.$fieldWrap.find(".label-item"),
												name:"click",
												events:function(){
											        that.$fieldWrap.find('.label-item').removeClass('checked');
											        $(this).addClass('checked');
											        var paramKey = $(this).attr("data-paramid")
											        that.$functionWrap.find('input').val(paramKey);
											        
											        //时间条件
								                    that.createTimeSelects();
								                    that.bindEvent({
														obj:that.$conditionWrap.find(".JS_conditionDate"),
														name:"change",
														events:function(){
															var conditionType = $(this).val();
									                        if(conditionType == 'year'){
									                            that.$conditionWrap.find(".JS_conditionDateS").empty().append(that.condYearSelect);
									                        } else if(conditionType == 'month'){
									                            that.$conditionWrap.find(".JS_conditionDateS").empty().append(that.condMonthSelect);
									                        } else if(conditionType == 'quarter'){
									                            that.$conditionWrap.find(".JS_conditionDateS").empty().append(that.condQuarterSelect);
									                        } else{
									                        	that.$conditionWrap.find(".JS_conditionDateS").empty();
									                        }
									                        if(that.$conditionWrap.find(".JS_conditionDateS").next('span.JS_btnTagCreate').length<1){
									                        	that.$conditionWrap.find(".JS_conditionDateS").after('<span class="JS_btnTagCreate btn btn-primary btn-create">生成</span>');
									                        }
									                        
									                        //结果
										                    /*that.createResultPreview();
										                    that.bindEvent({
																obj:that.$tagResultWrap.find(".JS_btnTagTest"),
																name:"click",
																events:function(){
																	//根据参数组合生成json
																	that.createComJSON();
																	var jsonstr = JSON.stringify(that.comJSON);
																	
																	//取结果
																	that.getJSON({
																		url:that.config.basePath + "/formulaController/getResult.do?function="+encodeURIComponent(jsonstr),
																		data:jsonstr,
																		callback:function(result){
																			if(that.config.debugEnable){
																				var val = 10 + (Math.random()*100).toFixed(2);
																			}else{
																				var val=result.data[0].tag;
																			}
								
																			if(val){
																				//获取tag唯一ID
																				if(!that.isEditing && !that.currentId){
																					var tagId = that.getUniqeId();
																					that.currentId = tagId;
																				}else{
																					var tagId = that.currentId;
																				}
																				that.tmpData.value = val;
									
																                //预览
																				that.$tagResultWrap.find(".JS_tagValue").text(val);
																				
																				var len = $("#tagTem").find("#"+tagId).length;
																				if(that.isEditing){
																					$("#tagTem").find("#"+tagId).empty().append(jsonstr);
																				}else{
																					var tagTem =  '<textarea style="display:none" id="'+tagId+'">'+jsonstr+'</textarea>';
																					$("#tagTem").append(tagTem);
																				}
																			}else{
																				//layer.alert('计算结果失败，尝试更改条件');
																			}
																		},
																		errorFun:function(result){
																			if(that.config.debugEnable){
																				this.callback(result);
																			}else{
																				var val=result.error;
															                	//预览
																				that.$tagResultWrap.find(".JS_tagValue").text(val);
																			}
																		}
																	})
																}
															});*/
														}
													});
													if(that.isEditing){
														that.$conditionWrap.find(".JS_conditionDate").change();
													}
												}
											});
				                    	}
				                    });
								}
							});
						}
					});//bind event end
					
					//editing触发绑定事件
					if(that.isEditing){
						that.$tableWrap.find("select").change();
					}
				},
				errorFun:function(){
					that.clearCustomWrap();
				}
			});
		},
		
		//结果预览
		createResultPreview:function(){
			var that = this;
			var restultTxt = '';
			if(this.isEditing){
        		//装载5
        		restultTxt = that.dataJSON[that.currentId].value;
        	}
            this.$tagResultWrap.empty().append('<p>结果预览：<span class="JS_btnTagTest btn btn-primary btn-xs">测试</span> <span class="JS_tagValue tags btn">'+restultTxt+'</span></p>');
		},
		
		//渲染时间条件区域内容
		createTimeSelects:function(){
			var that = this;
			//选择时间
            var conditionTable = '';
        	var timeType = '';
            var type1='',
            type2='',
            type3='';
        	if(this.isEditing){
        		//装载4
        		timeType = that.dataJSON[that.currentId].type?that.dataJSON[that.currentId].type:'';
        		type1 = that.dataJSON[that.currentId].year?that.dataJSON[that.currentId].year:'';
	            type2 = that.dataJSON[that.currentId].month?that.dataJSON[that.currentId].month:'';
	            type3 = that.dataJSON[that.currentId].season?that.dataJSON[that.currentId].season:'';
        	}
            var $condItem = $('<div class="form-inline" style="margin-bottom:10px"><div class="form-group"><label>选择时间: </label><select class="form-control input-sm JS_conditionDate">'
            +'<option>选择时间</option>'
            +'<option value="year" '+(timeType=='year'?'selected':'')+'>年度</option>'
            +'<option value="month" '+(timeType=='month'?'selected':'')+'>月度</option>'
            +'<option value="quarter" '+(timeType=='quarter'?'selected':'')+'>季度</option></select><div style="display:inline-block" class="JS_conditionDateS"></div></div></div>');
            
            
            var condYearOption = '';
            var condMonthOption = '';
            for ( var i = 2015; i<=2020; i++ ){
                condYearOption += '<option value ="'+ i +'" '+((i==type1)?'selected':'')+'>'+ i +'</option>';
            }
            for ( var i = 1; i<=12; i++ ){
                condMonthOption += '<option value ="'+ i +'" '+((i==type2)?'selected':'')+'>'+ i +'</option>';
            }
            var conQuarterOption = ('<option value="3" '+(('3'==type3)?'selected':'')+'>第一季度</option>'
            +'<option value="6" '+(('6'==type3)?'selected':'')+'>第二季度</option>'
            +'<option value="9" '+(('9'==type3)?'selected':'')+'>第三季度</option>'
            +'<option value="12" '+(('12'==type3)?'selected':'')+'>第四季度</option>');
            
            this.$conditionWrap.empty().append($condItem);
            
            this.condYearSelect =$('<select class="form-control input-sm JS_condYear">'+ condYearOption +'</select>');
            this.condMonthSelect = $('<select class="form-control input-sm JS_condYear">'+ condYearOption +'</select><select class="form-control input-sm JS_condMonth">'+ condMonthOption +'</select>');
            this.condQuarterSelect = $('<select class="form-control input-sm JS_condYear">'+ condYearOption +'</select><select class="form-control input-sm JS_condQuarter">'+ conQuarterOption +'</select>');
		},
		
		//要素
		getFiledTableData:function(params){
			var that = this;
			this.getJSON({
				url:that.config.basePath + "/trueDataController/getFieldList.do?modelId="+params.modelId,
				callback:function(result){
					//渲染要素模块
					var field = result;
					if(field.data && field.data.fields){
						var fieldTable = '';
                        var fields = field.data.fields;
                        var fieldItem = ''
                        //选择要素
                        for(var i=0,l=fields.length;i<l;i++){
		                	var checked = '';
		                	if(that.isEditing){
		                		//装载3
		                		if(('_t'+i)==that.dataJSON[that.currentId].t){
		                			checked = 'checked';
		                		}
		                	}
                            fieldItem += '<span class="label-item '+checked+'" data-paramid="_t'+ i +'" data-fieldname="'+ fields[i].name +'">'+ fields[i].note +'</span>'
                        }
                        fieldTable = $('<table class="table table-bordered"><colgroup><col width="15%" /></colgroup><tr><th>选择要素</th><td>'+ fieldItem +'</td></tr></table>');
                        that.$fieldWrap.empty().append(fieldTable);
                        //通知回调绑定事件
                        if(params.callback){
                        	params.callback();
                        }
                   	}
				},
				errorFun:function(){
					that.$fieldWrap.empty();
				}
			})
		},
		
		//渲染分组
		createGroupSpans:function(params){
			var that = this;
			var groups = params.groups;
    		var groupTable = '';
	        var groupItem = '';
	        //遍历分组
			for(var i=0,l=groups.length;i<l;i++){
				var groupHD = groups[i].name;
                var groupId = groups[i].id;
                var groupBD = '';
                var mxs = groups[i].mxlist;
                for(var j=0,cl=mxs.length;j<cl;j++){
                	var checked = '';
                	if(that.isEditing){
                		//装载2
                		if(mxs[j].guid==that.dataJSON[that.currentId].mxzbid){
                			checked = 'checked';
                		}
                	}
                	groupBD += '<span class="label-item '+checked+'" data-guid="'+ mxs[j].guid +'">'+ mxs[j].zbmc +'</span>';
                }
                groupItem += '<tr><th>'+ groupHD +'</th><td>'+ groupBD +'</td></tr>';
			}
			groupTable = $('<table data-tablename="'+ params.tableName +'" data-modelId="'+params.modelId+'" class="table table-bordered"><colgroup><col width="15%"></colgroup>'+ groupItem +'</table>');
			this.$groupWrap.empty().append(groupTable);
		},
		
		//指标下拉列表数据
		createTableSelects:function(tables){
			var that = this;
        	var tableOption = '<option>请选择指标</option>';
        	for(var i=0,l=tables.length;i<l;i++){
        		var selected = '';
        		if(that.isEditing){
        			//装载1
        			if(tables[i].modelId==that.dataJSON[that.currentId].zbid){
        				selected = 'selected';
        			}
        		}
        		tableOption += '<option '+selected+' value='+ tables[i].modelId +' data-tableName="'+ tables[i].tableName +'" data-tbKey="'+i+'">'+tables[i].modelName+'</option>';
        	}
        	var $tableItem = $('<div class="form-inline" style="margin-bottom:10px"><div class="form-group"><label>选择指标: </label><select class="form-control input-sm">'+ tableOption +'</select></div></div>');
            this.$tableWrap.empty().append($tableItem);
		},
		
		//重新封装ajax请求数据函数
		getJSON:function(params){
			var that = this;
			$.ajax({
	            type:"POST",
	            dataType:"jsonp",
	            data:params.data?params.data:'',
	            jsonp:"callback",
	            url: params.url,
	            cache: false,
	            async: false,
	            success:function(result){
	            	if(result && (result.error==null) && (result.success==true) && result.data){
			    		//pass
			    		if(params.callback){
			    			params.callback(result);
			    		}
			    	}else{
			    		//ajax data error
			    		console.log('getJSON Error', params);
			    		if(params.errorFun){
			    			params.errorFun(result);
			    		}
			    	}
		        }
		  	});
		},
		
		//重置容器内容
		clearCustomWrap:function(){
			this.$fieldWrap.empty();
	        this.$paramWrap.empty();
	        this.$functionWrap.empty();
	        this.$styleWrap.empty();
	        this.$tagResultWrap.empty();
	        this.$groupWrap.empty();
	        this.$conditionWrap.empty();
		},
		
		//根据参数生成comJSON
		createComJSON:function(){
			var that = this;
			var paramJSON = new Array;
			
	        var group = that.$groupWrap.find(".label-item.checked");
        	var _guId = group.attr('data-guid');
	
	        var _tableName = that.$groupWrap.find("table").attr('data-tablename');
	        var _groupId = that.$groupWrap.find("table").attr('data-modelId');
	
	        var _year = that.$conditionWrap.find('select.JS_condYear').val();
	        var _month = that.$conditionWrap.find('select.JS_condMonth').val();
	        var _quarter = that.$conditionWrap.find('select.JS_condQuarter').val();
	
	        _year = typeof _year != 'undefined' ? "='"+_year+"'" : "";
	        _month = typeof _month != 'undefined' ? "='"+_month+"'" : "";
	        _quarter = typeof _quarter != 'undefined' ? "='"+_quarter+"'" : "";
	
	        var _condition = {'month': _month, 'year': _year, 'season': _quarter, 'mxzbid': "='"+_guId+"'", 'zbid': "='"+_groupId+"'"}
	
	        var params = that.$fieldWrap.find(".label-item.checked");
	        params.each(function() {
	            var _paramId = $(this).attr('data-paramid');
	            var _fileNote = $(this).text();
	            var _fieldName = $(this).attr('data-fieldname');
	
	            var _paramItem = {'table': _tableName, 'note': _fileNote, 'field':_fieldName, 'condition':_condition};
	            var paramItem = {};
	            paramItem[_paramId] = _paramItem;
	
	            paramJSON.push(paramItem);
	        })
	        var _function = {'tag': $(params[0]).attr('data-paramid')}
	        //存入对象内
	        that.comJSON = {'param' : paramJSON, 'type': 1,  'result': _function};
	        that.tmpData = {
	        	zbid:_groupId,
	        	mxzbid:_guId,
	        	t:$(params[0]).attr('data-paramid'),
	        	type:that.$conditionWrap.find('select.JS_conditionDate').val(),
	        	year:that.$conditionWrap.find('select.JS_condYear').val(),
	        	season:that.$conditionWrap.find('select.JS_condQuarter').val(),
	        	month:that.$conditionWrap.find('select.JS_condMonth').val()
	        }
		},
		
		//容器赋值
		customWrapsAligin:function(){
			this.$tableWrap      = $('#tagWrap .JS_tableWrap');
		    this.$groupWrap      = $('#tagWrap .JS_groupWrap');
		    this.$fieldWrap      = $('#tagWrap .JS_fieldWrap');
		    this.$conditionWrap  = $('#tagWrap .JS_conditionWrap');
		    this.$paramWrap      = $('#tagWrap .JS_paramWrap');
		    this.$functionWrap   = $('#tagWrap .JS_functionWrap');
		    this.$styleWrap      = $('#tagWrap .JS_styleWrap');
		    this.$tagResultWrap  = $('#tagWrap .JS_resultWrap');
		},
		
		//容器初始化
		createCustomWraps:function(){
			$('#twEditor').append('<div id="paramWrap"></div><div id="tagTem"></div>')
		    	.append('<div style="margin:20px 20px 0 20px;" class="row" id="tagWrap"></div>')
		    	.find("#tagWrap")
		        .append('<div class="JS_tableWrap"></div>')
		        .append('<div class="JS_groupWrap"></div>')
		        .append('<div class="JS_fieldWrap"></div>')
		        .append('<div class="JS_conditionWrap"></div>')
		        .append('<div class="JS_paramWrap"></div>')
		        .append('<div class="JS_functionWrap"></div>')
		        .append('<div class="JS_styleWrap"></div>')
		        .append('<div class="JS_resultWrap"></div></div>');
		    //绑定创建的窗口到tag对象内
		    this.customWrapsAligin();
		},
		
		//生成唯一ID
		getUniqeId:function(){
			return this.idPrefix + (this.globalNum++);
		},
		
		//覆盖配置
		updateOption:function(options){
			this.config = $.extend(true, this.config, options);
		},
		
		//对于自定义标签的拓展插件
		customToolPlugin:function(params){
			var that = params.that;
			var editor = params.this;
	        var txt = editor.txt;
	        var $txt = txt.$txt;
	        // 说明：设置了 max-height 之后，$txt.parent() 负责滚动处理
	        var $currentTxt = editor.useMaxHeight ? $txt.parent() : $txt;
	        var $currentTag;
	
	        // 用到的dom节点
	        var isRendered = false;
	        var $toolbar = $('<div class="txt-toolbar"></div>');
	        var $triangle = $('<div class="tip-triangle"></div>');
	        var $delete = $('<a href="#"><i class="wangeditor-menu-img-trash-o"></i></a>');
	        var $edit = $('<a href="#"><i class="wangeditor-custom-icon-edit"></i></a>');
	        
	        // 渲染到页面
	        function render() {
	            if (isRendered) {
	                return;
	            }
	            
	            // 绑定事件
	            bindEvent();
	
	            // 拼接 渲染到页面上
	            $toolbar.append($triangle)
	                    .append($delete)
	                    .append($edit);
	            editor.$editorContainer.append($toolbar);
	            isRendered = true;
	        }
	        
	        // 绑定事件
	        function bindEvent() {
	            // 统一执行命令的方法
	            var commandFn;
	            function command(e, callback) {
	                if (commandFn) {
	                    editor.customCommand(e, commandFn, callback);
	                }
	            }
	
	            // 删除
	            $delete.click(function (e) {
	            	that.currentId = false;
	            	
	                commandFn = function () {
	                    $currentTag.remove();
	                };
	                command(e, function () {
	                    setTimeout(hide, 100);
	                });
	            });
	
	            $edit.click(function(e) {
	                // var random = E.random();
	                // var rangeElem = editor.getSelfOrParentByName('i','tags');
	                // console.log(rangeElem);
	
	                var ct = $currentTag;
	                var tagId = $currentTag.attr('data-id');
	                that.currentId = tagId;
	
	                // var tag = JSON.parse($("#"+$currentTag.attr('data-id')).val());
//	                var tag ='';
//	                if($("#"+$currentTag.attr('data-id')).length>0){
//	                    tag = JSON.parse($("#"+tagId).val());
//	                } else{
//	                    var taglabel = $currentTag.html();
//	                    var star = taglabel.indexOf("<!--TrueDATA[");
//	                    tag = JSON.parse(taglabel.slice(star+13,taglabel.length-4));
//	                }
	
	//              $.each(tag.param, function(key, value){
	//                  var paramKey = Object.keys(value)[0];
	//
	//                  $paramConditionItem = $('<div class="paramval-item"><span class="JS_btnDelParam delparam"><i class="fa fa-close"></i></span><span>'+ paramKey +'</span><textarea style="display:none">'+ JSON.stringify(value) + '</textarea></div>');
	//                  //计算可选标签已隐藏
	////                  $paramWrap.append($paramConditionItem);
	// 
	//              });
	
	//              var paramKey = tag.result.tag;
	                //计算公式已隐藏
	//              setFunction(paramKey);
	
	                //rewrite
	                that.isEditing = true;
	                that.layerIn({e:e,editor:editor});
	            });//edit click end
	        }
	        
	        // 显示 toolbar
	        function show() {
	            if (editor._disabled) {
	                // 编辑器已经被禁用，则不让显示
	                return;
	            }
	            if ($currentTag == null) {
	                return;
	            }
	            $(".tags").removeClass('clicked');
	            $currentTag.addClass('clicked');
	            var tagPosition = $currentTag.position();
	            var tagTop = tagPosition.top;
	            var tagLeft = tagPosition.left;
	            var tagHeight = $currentTag.outerHeight();
	            var tagWidth = $currentTag.outerWidth();
	
	            // --- 定位 toolbar ---
	            // 计算初步结果
	            var top = tagTop + tagHeight;
	            var left = tagLeft;
	            var marginLeft = 0;
	
	            var txtTop = $currentTxt.position().top;
	            var txtHeight = $currentTxt.outerHeight();
	            if (top > (txtTop + txtHeight)) {
	                // top 不得超出编辑范围
	                top = txtTop + txtHeight;
	            }
	
	            // 显示（方便计算 margin）
	            $toolbar.show();
	
	            // 计算 margin
	            var width = $toolbar.outerWidth();
	            marginLeft = tagWidth / 2 - width / 2;
	
	            // 定位
	            $toolbar.css({
	                top: top + 5,
	                left: left,
	                'margin-left': marginLeft
	            });
	            // 如果定位太靠左了
	            if (marginLeft < 0) {
	                // 得到三角形的margin-left
	                $toolbar.css('margin-left', '0');
	                $triangle.hide();
	            } else {
	                $triangle.show();
	            }
	        }
	        
	        // 隐藏 toolbar
	        function hide() {
	            if ($currentTag == null) {
	                return;
	            }
	//          $currentTag.removeClass('clicked');
	//          $currentTag = null;
	            $toolbar.hide();
	        }
	        
	        // click tag 事件
	        $currentTxt.on('click', '.tags', function (e) {
	            var $tag = $(e.currentTarget);
	
	            // 渲染
	            render();
	
//	            if ($currentTag && ($currentTag.get(0) === $tag.get(0))) {
//	                setTimeout(hide, 100);
//	                return;
//	            }
	
	            // 显示 toolbar
	            $currentTag = $tag;
	            show();
	
	            // 阻止冒泡
	            e.preventDefault();
	            e.stopPropagation();
	            
	        }).on('click keydown scroll', function (e) {
	            setTimeout(hide, 100);
	        });
	        that.WE.$body.on('click keydown scroll', function (e) {
	            setTimeout(hide, 100);
	        });
		},
		
		//获取窗口大小
		getPageSize:function(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight}}var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth}else{windowWidth=self.innerWidth}windowHeight=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight}else{if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight}}}if(yScroll<windowHeight){var pageHeight=windowHeight}else{var pageHeight=yScroll}if(xScroll<windowWidth){var pageWidth=xScroll}else{var pageWidth=windowWidth}var arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize}
	}//prototype end

	
	var TrueTagsObj = new trueTags().init();
	console.log(TrueTagsObj);
})();